﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace System
{
    public static class StringExtensions
    {
        public static bool Like(this string _string, string text)
        {
            if (_string == text)
                return true;

            string s1 = _string.ToLower();
            string s2 = text.ToLower();

            int i1 = 0;
            int i2 = 0;
            int diffCount = 0;

            while (i1 < s1.Length && i2 < s2.Length)
            {
                if (s1[i1] != s2[i2])
                {
                    diffCount++;

                    if (i1 < s1.Length - 1 && i2 < s2.Length - 1)
                    {
                        if (s1[i1 + 1] != s2[i2 + 1] && s1[i1 + 1] == s2[i2])
                            i1++;
                        else if (s1[i1 + 1] != s2[i2 + 1] && s1[i1] == s2[i2 + 1])
                            i2++;
                    }
                }

                i1++;
                i2++;
            }

            diffCount += (s1.Length - i1) + (s2.Length - i2);

            return diffCount <= Math.Ceiling(Math.Min(_string.Length, text.Length) / 3.0f);
        }
        public static int IndexOfAny(this string me, params char[] values)
        {
            return me.IndexOfAny(values);
        }

        public static string[] SplitWords(this string me)
        {
            return me.Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
        }
        public static string[] SplitLines(this string me)
        {
            return me.Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
        }
    }
}
